package org.southyin.controller;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AServlet implements Servlet {

    public AServlet() {
        System.out.println("构造器");
    }

    // 初始化方法
    public void init(ServletConfig servletConfig) throws ServletException {
        System.out.println("初始化");
    }

    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
        HttpServletRequest req = ((HttpServletRequest) request);
        HttpServletResponse resp = (HttpServletResponse) response;
        String method = req.getMethod();
       if("GET".equals(method)){
           doGet(req,resp);
       }else if("POST".equals(method)){
           doPost(req,resp);
       }
    }

    public void doGet(HttpServletRequest req, HttpServletResponse resp){
        System.out.println(123);
    }

    public void doPost(HttpServletRequest req, HttpServletResponse resp){
        System.out.println(456);
    }


    public void destroy() {
        System.out.println("销毁");
    }

    public ServletConfig getServletConfig() {
        return null;
    }

    public String getServletInfo() {
        return null;
    }
}
